package sctu.edu.java.year2016.team01.xuhanmei.day20160609.TryUDP;

import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

/**
 * Created by Administrator on 2016/6/9.
 */
public class UDPServer {
    public static void main(String[] args) throws Exception {
        DatagramSocket ds = new DatagramSocket(5678);//码头端口号

        byte buf[] = new byte[1024];
        DatagramPacket dp = new DatagramPacket(buf, buf.length);//集装箱

        try {
            while (true) {
                ds.receive(dp);//ds码头接收dp集装箱的数据

                ByteArrayInputStream bais = new ByteArrayInputStream(dp.getData());
                DataInputStream dis = new DataInputStream(bais);
                System.out.println(dis.readLong());
            }
        } catch (Exception e) {
            e.printStackTrace();
            ds.close();//关闭码头
        }
    }
}
